package com.jdkreader.concurrency.concurrent.simulation;

import java.util.Random;
import java.util.concurrent.TimeUnit;


/**
 * 顾客生成器，模拟不断的产生顾客
 */
public class CustomerGenerator implements Runnable{

    private CustomerLine cl;
    private static Random random=new Random(47);
    public CustomerGenerator(CustomerLine line){
        cl=line;
    }

    public void run(){
        try{
            while(!Thread.interrupted()){
                //模拟顾客进店的间隔
                TimeUnit.SECONDS.sleep(random.nextInt(300));
                cl.put(new Customer(random.nextInt(1000)));
            }
        }catch(InterruptedException e){
            System.out.println("CustomerGenerator Interrupted");
            e.printStackTrace();
        }
        System.out.println("CustomerGenerator terminating");
    }
}
